/*
 * AddItemsStrutsAction.java
 *
 * Created on July 7, 2007, 3:56 PM
 */

package com.abbh.libcommunity.struts.actions;

import com.abbh.libcommunity.bo.impl.ItemBOImpl;
import com.abbh.libcommunity.dao.LCHibernateUtil;
import com.abbh.libcommunity.model.Item;
import com.abbh.libcommunity.struts.beans.AddItemsStrutsActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.hibernate.Session;
import org.hibernate.Transaction;


/**
 *
 * @author Atef A. Ahmed
 * @version
 */

public class AddItemsStrutsAction extends Action {
    
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */

    
    
    public ActionForward execute(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
          AddItemsStrutsActionForm a=(AddItemsStrutsActionForm)form;
          
          Item item=new Item();
          item.setId(a.getUserId());
          item.setIsbn(a.getIsbn());
          item.setTitle(a.getTitle());
          item.setDescription(a.getDescription());
         
          item.setYears(a.getYear());
          
          item.setRating(a.getRating());
          item.setItemType(a.getItemType());
          item.setItemCategory(a.getItemCategory());
          item.setPublisher(a.getPublisher());
          
          
      //   Session s=com.abbh.libcommunity.dao.LCHibernateUtil.currentSession();
    //     Transaction t=s.beginTransaction();
          
          ItemBOImpl saveitem=new ItemBOImpl();
          saveitem.saveItem(item);
          
       //   s.save(item);
        
        return mapping.findForward(SUCCESS);
        
    }
}
